<template>
  <div>
    <el-form :inline="true" :model="formData" class="demo-form-inline">
      <el-form-item label="用户ID">
        <el-input v-model="formData.uId" placeholder="查询用户ID"></el-input>
      </el-form-item>
      <el-form-item label="用户名">
        <el-input v-model="formData.uName" placeholder="模糊查询用户名"></el-input>
      </el-form-item>
      <el-form-item label="用户性别">
        <el-select v-model="formData.sex" placeholder="用户性别">
          <el-option label="全部" value="0"></el-option>
          <el-option label="男" value="1"></el-option>
          <el-option label="女" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="账号状态">
        <el-select v-model="formData.region" placeholder="账号状态">
          <el-option label="正常" value="0"></el-option>
          <el-option label="封号" value="1"></el-option>
          <el-option label="注销" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="query">查询</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" stripe style="width: 100%" :show-overflow-tooltip="true" align="center" height="700">
      <el-table-column prop="reginDate" label="注册时间" fixed="left" align="center"></el-table-column>
      <el-table-column prop="userId" label="用户ID" align="center"></el-table-column>
      <el-table-column prop="userName" label="用户昵称" align="center"></el-table-column>
      <el-table-column prop="userAge" label="用户年龄" align="center"></el-table-column>
      <el-table-column prop="userSex" label="用户性别" align="center"></el-table-column>
      <el-table-column prop="userDesc" label="用户描述" align="center"></el-table-column>
      <el-table-column prop="userState" label="账号状态" align="center"></el-table-column>
      <el-table-column prop="userAge" label="用户年龄" align="center"></el-table-column>
      <el-table-column prop="weiboLink" label="用户微博链接" align="center"></el-table-column>
      <el-table-column prop="mailLink" label="用户邮箱链接" align="center"></el-table-column>
      <el-table-column prop="options" label="操作" min-width="150" align="center"></el-table-column>
    </el-table>

    <div class="page">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page="currentPage" :page-sizes="[100, 200, 300, 400]" :page-size="100"
                     layout="total, sizes, prev, pager, next, jumper" :total="400">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import AxiosUtil from '@/util/AxiosUtil'

  export default {
    name: "UserIndex",
    data() {
      return {
        formData: {
          uId: '',
          sex: '',
          state: '',
          uName: ''
        },
        tableData: [],
        currentPage: 1
      }
    },
    methods: {
      query() {
        let params = {};
        let data = this.formData;
        for (let key in data) {
          if (data[key] !== '') {
            params[key] = data[key];
          }
        }
        AxiosUtil.get('/user/list', params).then(res => {
          if (res.code === 200) {
            this.tableData = res.data
          }
        }).catch(e => {
          alert(e)
        })
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      }
    }
  }
</script>

<style scoped>
  .page {
    width: 100%;
    text-align: center;
    margin-top: 20px;
  }
</style>
